/**
 * Copyright (c) 2004-2015 All Rights Reserved.
 */
package com.zbest.component.session;


/**
 * @see com.zbest.component.session.SessionRepository
 *
 * @author czhou3306@gmail.com
 * @version $Id: SessionRepositoryImpl.java, v0.1 2015年6月9日 上午10:19:22 czhou3306@gmail.com Exp $
 */
public class RedisSessionRepositoryImpl implements SessionRepository {

    /**path："/"*/
    protected String   sessionPath;

    /**domainName:.qiangungun.com，由antx中配置传入*/
    protected String   domainName;

    /**超时时间，跟最后一次操作时间进行比较*/
    protected int      expireTime;

    /**redis客户端*/
  //  protected Redisson sessionRedis;

    /** 
     * @see com.zbest.component.session.SessionRepository#create()
     */
    @Override
    public QianSession create() {

        RedisSession session = new RedisSession();
        session.setGmtCreate(System.currentTimeMillis());
        session.setExpireTime(this.expireTime);
        session.setGmtLastAccess(System.currentTimeMillis());
        session.setMaxInactiveInterval(this.expireTime);
        session.setSessionId(SessionIdGenerator.generate());
        return session;
    }

    /** 
     * @see com.zbest.component.session.SessionRepository#save(com.zbest.component.session.QianSession)
     */
    @Override
    public void save(QianSession session) {

        /* RBucket<QianSession> bucket = sessionRedis.getBucket(session.getSessionId());
         bucket.set(session, expireTime, TimeUnit.SECONDS);*/
    }

    /** 
     * @see com.zbest.component.session.SessionRepository#getSession(java.lang.String)
     */
    @Override
    public QianSession getSession(String id) {/*

                                              RBucket<QianSession> bucket = sessionRedis.getBucket(id);
                                              return bucket.get();
                                              */
        return null;
    }

    /** 
     * @see com.zbest.component.session.SessionRepository#delete(java.lang.String)
     */
    @Override
    public void delete(String id) {/*

                                   RBucket<QianSession> bucket = sessionRedis.getBucket(id);
                                   bucket.delete();
                                   */
    }

    /**
     * Setter method for property <tt>sessionPath</tt>.
     * 
     * @param sessionPath value to be assigned to property sessionPath
     */
    public void setSessionPath(String sessionPath) {
        this.sessionPath = sessionPath;
    }

    /**
     * Setter method for property <tt>domainName</tt>.
     * 
     * @param domainName value to be assigned to property domainName
     */
    public void setDomainName(String domainName) {
        this.domainName = domainName;
    }

    /**
     * Setter method for property <tt>expireTime</tt>.
     * 
     * @param expireTime value to be assigned to property expireTime
     */
    public void setExpireTime(int expireTime) {
        this.expireTime = expireTime;
    }

    /**
     * Getter method for property <tt>sessionPath</tt>.
     * 
     * @return property value of sessionPath
     */
    public String getPath() {
        return sessionPath;
    }

    /**
     * Getter method for property <tt>domainName</tt>.
     * 
     * @return property value of domainName
     */
    public String getDomainName() {
        return domainName;
    }

    /** 
     * @see com.zbest.component.session.SessionRepository#getDomain()
     */
    @Override
    public String getDomain() {
        return domainName;
    }

    /** 
     * @see com.zbest.component.session.SessionRepository#reclocking(com.zbest.component.session.QianSession)
     */
    @Override
    public void reclocking(QianSession gungunSession) {/*
                                                       RBucket<QianSession> bucket = sessionRedis.getBucket(gungunSession.getSessionId());
                                                       bucket.expire(expireTime, TimeUnit.SECONDS);
                                                       */
    }

    /**
     * Setter method for property <tt>sessionRedis</tt>.
     * 
     * @param sessionRedis value to be assigned to property sessionRedis
     */
  /*  public void setSessionRedis(Redisson sessionRedis) {
        this.sessionRedis = sessionRedis;
    }*/
}
